package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class FirstOracleJdbc {
    public static void main(String[] args) {
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection(
                    "jdbc:oracle:thin:@10.10.3.237:1521:tarena", "openlab",
                    "open123");
            st = con.createStatement();
            String sql = "select * from rock_stu";
            rs = st.executeQuery(sql);
            while (rs.next()) {
                System.out.print("id=" + rs.getInt("id"));
                System.out.print(",  name=" + rs.getString("name"));
                System.out.println(",  birthday=" + rs.getDate("birthday"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
            } catch (Exception e) {
            }

            try {
                st.close();
            } catch (Exception e) {
            }

            try {
                con.close();
            } catch (Exception e) {
            }
        }
    }
}